package br.com.projeto.dao.hql;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import br.com.projeto.sakila.bean.Address;
import br.com.projeto.sakila.bean.Film;

public class AddressDao {
	private SessionFactory sessionFactory;
	private Session session;

	public AddressDao(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	public long buscarAddress(){
		session = sessionFactory.openSession();
		long tempoInicial = System.currentTimeMillis(); 
		List<Address> listaAddress = new ArrayList<>();
		try{		
			listaAddress = session.createQuery("from Address").list();
			
			session.close();
		} catch (Exception e){
			System.err.println("Erro ");
		}
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;

		return tempo;
	}
	
	public void listarAddress(List<Address> lista){
		System.out.println("---------------------------");
		for (Address address : lista) {
			System.out.println("id : " + address.getId());
			System.out.println("address Member : " + address.getAddressMember());
			System.out.println("address2 : " + address.getAddress2());
			System.out.println("postalCode : " + address.getPostalCode());
			System.out.println("phone : " + address.getPhone());

			System.out.println("---------------------------");
		}
	}
}
